<!--
 * @Description: 
 * @Author: wangqi
 * @Date: 2021-06-11 09:59:35
 * @LastEditTime: 2021-06-11 11:31:52
-->
<script>
    {
        // 试寻找字符串中，连续重复次数最多的字符。
        let str = 'abbbccccc';

        function maxRepeat(str) {
            let i = 0;
            let j = 1;
            // 最大重复次数
            let maxRepeatCount = 0;
            // 最多重复次数字符
            let maxRepeatChar = ``;

            while (j <= str.length) {
                if (str[i] != str[j]) {
                    if (j - i > maxRepeatCount) {
                        maxRepeatCount = j - i;
                        maxRepeatChar = str[i];
                    }
                    i = j;
                }
                j++;
            }
            console.log(maxRepeatChar + ':' + maxRepeatCount + '次')
        };

        maxRepeat(str);

    }
</script>